package com.lei.chinese_herbal_medicine.Configuration;

import com.lei.chinese_herbal_medicine.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {
    @Value("${interceptor.path_patterns}")
    private String pathPatterns;

    @Value("#{'${interceptor.exclude_path_patterns}'.split(',')}")
    private List<String> excludePathPatterns;
    @Bean
    public HandlerInterceptor getInterceptor(){
        return new LoginInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器，并指定拦截的路径
        registry.addInterceptor(getInterceptor()).addPathPatterns(pathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}
